#define DEBUG
#include <cstdio>
#define INF 0x7ffffff
#define MAXN 3000
#define MAXM 5000

using namespace std;

void swap(int &a, int &b) {
  int t;
  t=a, a=b, b=t;
}

class Graph {
public:
  int n, m, ind[MAXN+1], to[MAXM+1], link[MAXM+1], dis[MAXN+1][MAXN+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void calcDis() {
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=n; j++) {
	dis[i][j] = -1;
      }
      static int que[MAXN+1];
      dis[i][i]=0;
      que[1] = i;
      for (int h=0, t=1; h<t;) {
	h = h+1;
	for (int j=ind[que[h]]; j; j=link[j]) {
	  if (dis[i][to[j]]<0) {
	    dis[i][to[j]] = dis[i][que[h]]+1;
	    que[++t] = to[j];
	  }
	}
      }
    }
  }
};

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0.out", "w", stdout);
#endif
  
  static Graph g, ug;
  int n, m;
  scanf("%d %d", &n, &m);
  g.n = ug.n = n;
  for (int i=1; i<=m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v);
    ug.addSide(v, u);
  }
  g.calcDis(), ug.calcDis();

  static int maxDis[2][MAXN+1][3][2];
  for (int i=1; i<=n; i++) {
    for (int j=0; j<3; j++) {
      maxDis[0][i][j][1] = maxDis[1][i][j][1] = -1;
    }
    for (int j=1; j<=n; j++) {
      int temp=ug.dis[i][j], tpos=j;
      for (int k=0; k<3; k++) {
	if (maxDis[0][i][k][1]<temp) {
	  swap(maxDis[0][i][k][0], tpos);
	  swap(maxDis[0][i][k][1], temp);
	}
      }
      temp=g.dis[i][j], tpos=j;
      for (int k=0; k<3; k++) {
	if (maxDis[1][i][k][1]<temp) {
	  swap(maxDis[1][i][k][0], tpos);
	  swap(maxDis[1][i][k][1], temp);
	}
      }
    }
  }

  static int ans[5];
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=n; j++) {
      if (g.dis[i][j]>0) {
	for (int k=0; k<3; k++) {
	  if (maxDis[0][i][k][1]>0 && maxDis[0][i][k][0]!=j) {
	    for (int l=0; l<3; l++) {
	      if (maxDis[1][j][l][1]>0 && maxDis[1][j][l][0]!=i && maxDis[1][j][l][0]!=maxDis[0][i][k][0]) {
		if (ans[0]<g.dis[i][j]+maxDis[0][i][k][1]+maxDis[1][j][l][1]) {
		  ans[0] = g.dis[i][j]+maxDis[0][i][k][1]+maxDis[1][j][l][1];
		  ans[1] = maxDis[0][i][k][0];
		  ans[2] = i;
		  ans[3] = j;
		  ans[4] = maxDis[1][j][l][0];
		}
	      }
	    }
	  }
	}
      }
    }
  }

  printf("%d %d %d %d", ans[1], ans[2], ans[3], ans[4]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
